package 品牌管理;

import java.sql.*;
import java.util.ArrayList;

public class 添加品牌 {
    public static void main(String[] args) {
        ArrayList<Brand> brandList = new ArrayList<>();
        Connection conn = null;
        Brand b = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            String url = "jdbc:mysql://localhost:3306/db_jdbc_demo?characterEncoding=utf8&useSSL=false&serverTimezone=UTC";
            String user = "root";
            String pass = "1234";
            conn = DriverManager.getConnection(url, user, pass);
            String sql = "INSERT INTO t_brand (id,brand_name,company_name,ordered,description,status) VALUES (?,?,?,?,?,?)";
            pstmt = conn.prepareStatement(sql);
            pstmt.setInt(1,6);
            pstmt.setString(2,"可口可乐");
            pstmt.setString(3,"可口可乐有限公司");
            pstmt.setInt(4,100);
            pstmt.setString(5,"解渴，怡神");
            pstmt.setInt(6,1);
            int i = pstmt.executeUpdate();
            if (i == 1){
                System.out.println("添加成功");
            }else {
                System.out.println("添加失败");
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                pstmt.close();
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}
